//
//  CameraModel.m
//  TengineTwo
//
//  Created by StandardUser on 04/03/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CameraModel.h"
#import "CGPointExtension.h"

@implementation CameraModel

@synthesize viewportWidth;
@synthesize viewportHeight;

@synthesize position;
@synthesize zoom;

- (id)initWithWidth:(float)w andHeight:(float)h {
    self = [super init];
    if (self) {
        zoom = 1.0;
        viewportWidth = w;
        viewportHeight = h;
        position = ccp(0,0);
    }
    return self;
}

-(void)applyCameraTransformTo:(CCLayer*)layer
{
    //CGPoint translation = ccpSub(ccp(viewportWidth*0.5, viewportHeight*0.5), position);
    
    layer.anchorPoint = ccp((1.0f/viewportWidth) * position.x, (1.0f/viewportHeight) * position.y);
    layer.scale = zoom;
    //layer.position = translation;
}
    
#pragma mark accessors
                              
-(void)setX:(float)value
{
    position.x = value;
}
-(float)x
{
    return position.x;
}
-(void)setY:(float)value
{
    position.y = value;
}
-(float)y
{
    return position.x;
}

@end
